<template>
	<div style="margin-top: 20%;">
		<!-- 入库 -->
		<view class="card_back" @click="goToPage('/pages/material/warehouse/index')"
			style="background-image: url('https://czsc.oss-cn-beijing.aliyuncs.com/mini/material_warehouse.jpg');">
			<div class="card_title">
				物资入库
			</div>
		</view>
		<!-- 出库 -->
		<view class="card_back" @click="goToPage('/pages/material/issue/index')"
			style="background-image: url('https://czsc.oss-cn-beijing.aliyuncs.com/mini/material_Issue.jpg');">
			<div class="card_title">
				物资出库
			</div>
		</view>
		<!-- 统计数量 -->
		<!-- <view class="card_back" @click="goToPage('/pages/material/num/index')"
			style="background-image: url('https://czsc.oss-cn-beijing.aliyuncs.com/mini/material_num.jpg');">
			<div class="card_title">
				物资实时统计
			</div>
		</view> -->
		<!-- 扫码 -->
		<div style="width: 95%;margin: auto;">
			<van-button type="primary" block color="#4142F4" @click="scanCodeMaterial()">扫一扫</van-button>
		</div>
	</div>
</template>

<script>
	import { BaseUrl } from '@/util/util.js';
	const PrefixUrl = BaseUrl();
	export default {
		data() {
			return {

			}
		},
		created() {
			if (uni.getStorageSync('openid') === '' || new Date() - uni.getStorageSync('getday') > 1296000000) {
				uni.redirectTo({
					url: '/pages/sq/sq'
				});
			} else {
				uni.request({
					method: 'POST',
					// url: 'https://www.gjegm.ltd/czsczq/wxuser/getOpenid',
					url: PrefixUrl + '/wxuser/getOpenid',
					data: {
						openid: uni.getStorageSync('openid')
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if (res.data.obj) {
							uni.removeStorageSync('token');
							uni.setStorageSync('userid', res.data.obj2.userid);
							uni.setStorageSync('username', res.data.obj2.username);
							uni.setStorageSync('userbdst', res.data.obj2.bdst);
							uni.setStorageSync('userPermission', res.data.obj2.wxPermission);
							// 获取Token
							uni.request({
								method: 'GET',
								url: PrefixUrl + '/userinfo/getToken',
								data: {
									name: '1',
									bdst: '1',
									department: '1'

								},
								header: {
									'content-type': 'application/x-www-form-urlencoded'
								},
								success: (res) => {
									uni.setStorageSync('token', res.data);
								}
							});

						} else {
							uni.redirectTo({
								url: '/pages/band/band_openid'
							});
						}

					}
				});
			}
		},
		methods: {
			goToPage(url) {
				//保留当前页面，跳转到应用内的某个页面，使用uni.navigateBack可以返回到原页面。
				uni.navigateTo({
					url: url
				});

			},
			scanCodeMaterial(){
				uni.scanCode({
					success: function (res) {
						uni.navigateTo({
							url: "/pages/material/scan/index?id=" + res.result
						});
					}
				});
			}
		}
	}
</script>

<style>
	.card_back {
		width: calc(100% - 100rpx);
		;
		background-color: burlywood;
		margin: 60rpx 20rpx;
		border-radius: 20rpx;
		text-align: center;
		padding: 30rpx;
		background-size: 85%;
	}

	.card_title {
		padding: 80rpx;
		font-size: 48rpx;
		color: white;
	}
</style>
